package com.xjtu.platform.admin.role.Impl;

import com.xjtu.platform.admin.role.ChangeWebDto;
import com.xjtu.platform.admin.role.DeleteDto;
import com.xjtu.platform.admin.role.RoleDto;
import com.xjtu.platform.admin.role.RoleService;
import com.xjtu.platform.admin.role.dao.RoleDao;
import com.xjtu.platform.common.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleDao roleDao;

    @Override
    public Map<String, Object> getRoleInfo(RoleDto roleDto) {
        return Utils.getPage(roleDto,()->roleDao.findRole(roleDto));
    }

    @Override
    public boolean changeWeb(ChangeWebDto changeWebDto) {
        try {
            roleDao.changeWeb(changeWebDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deleteRole(DeleteDto deleteDto) {
        try {
            roleDao.deleteRole_model(deleteDto);
            roleDao.deleteRole(deleteDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
